import toastYY from "../toastY/toast.vue"

let $vmToast;

export const toastY = {
  install(Vue){
    const Toast = Vue.extend(toastYY)

    if (!$vmToast) {
      $vmToast = new Toast({
        el: document.createElement('div')
      })
      document.body.appendChild($vmToast.$el)
    }
    let show = () => {
      $vmToast.show = true;
      setTimeout(() => {
        $vmToast.contentShow = true;
      }, 50);
    };

    let hide = (time) => {
      setTimeout(() => {
        $vmToast.contentShow = false;
        setTimeout(() => {
          $vmToast.show = false;
        }, 400);
      }, time);
    };

    Vue.prototype._toastY = (content, iconClass, time) => {
      time = time || 1200;
      $vmToast.content = content;
      $vmToast.iconClass = iconClass || false;
      show();
      hide(time);
    }
  }
}
/*
 this.toastY(content, iconClass, time);
 */
